package org.tech4j.edi.common.result;

import java.io.Serial;
import java.io.Serializable;

/**
 * @program: tech4j
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/7 10:36
 **/
public class DefaultEdiEntity implements Serializable {
    @Serial
    private static final long serialVersionUID = -7273004797526102732L;

    private static final int ERROR = 500;

    private Integer code;

    private String message;
    
    private Object data;

    public DefaultEdiEntity(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    /**
     * return error .
     *
     * @param msg error msg
     * @return {@linkplain DefaultEdiEntity}
     */
    public static DefaultEdiEntity error(final String msg) {
        return error(ERROR, msg);
    }

    /**
     * return error .
     *
     * @param code error code
     * @param msg  error msg
     * @return {@linkplain DefaultEdiEntity}
     */
    public static DefaultEdiEntity error(final int code, final String msg) {
        return get(code, msg, null);
    }

    /**
     * return error .
     *
     * @param code error code
     * @param msg  error msg
     * @param data the data
     * @return {@linkplain DefaultEdiEntity}
     */
    public static DefaultEdiEntity error(final int code, final String msg, final Object data) {
        return get(code, msg, data);
    }

    /**
     * return timeout .
     *
     * @param msg error msg
     * @return {@linkplain DefaultEdiEntity}
     */
    public static DefaultEdiEntity timeout(final String msg) {
        return error(ERROR, msg);
    }

    private static DefaultEdiEntity get(final int code, final String msg, final Object data) {
        return new DefaultEdiEntity(code, msg, data);
    }
}
